package org.tinygroup.channel.protocol.impl;

import java.util.List;

import org.tinygroup.channel.protocol.ProtocolInInterface;
import org.tinygroup.channel.protocol.ProtocolListener;
import org.tinygroup.context.Context;
import org.tinygroup.context.util.ContextFactory;

public abstract class AbstractProtocolInInterface<RequestMsg, ResponseMsg> extends
		AbstractProtocolInterface implements
		ProtocolInInterface<RequestMsg, ResponseMsg>{

	public ResponseMsg received(RequestMsg requestMsg) {
		List<ProtocolListener<?,?>> listeners = getListeners();
		ProtocolListenerChain chain = new ProtocolListenerChain(listeners);
		Context context = ContextFactory.getContext();
		chain.pre(requestMsg, context);
		ResponseMsg responseMsg = realDeal(requestMsg,context);
		chain.post(requestMsg,responseMsg, context);
		return responseMsg;
	}
	protected abstract ResponseMsg realDeal(RequestMsg requestMsg,Context context);
	
	

}
